package query

import (
	"ssdevice/common/dto"
)

type RuleGetReq struct {
	Id             string `form:"id"  search:"type:exact;column:id;table:sys_rule"`
	Name           string `form:"name"  search:"type:contains;column:name;table:sys_rule"`
	Status         string `form:"status"  search:"type:exact;column:status;table:sys_rule"`
	Creator        string `search:"type:exact;column:creator;table:sys_rule"`
	AgencyId       string `search:"type:exact;column:agency_id;table:sys_rule"`
	dto.Pagination `search:"-"`
	dto.OrderBy    `search:"-"`
	dto.UserInfo   `search:"-"`
}

func (m *RuleGetReq) GetNeedSearch() interface{} {

	currentUserId := m.UserInfo.UserId
	currentUserAgencyId := m.UserInfo.AgencyId
	// 非租户，非admin
	if currentUserId != currentUserAgencyId {
		// 查不到规则
		//m.Id = " "
		// 非租户查自己的
		m.Creator = currentUserId

	} else if currentUserId != "1" {
		// 租户查自己和下级的
		m.AgencyId = currentUserId
	}

	// admin查所有规则

	return *m
}
